import pool from "../connect/db";
import { Idb, IWheres } from "./type";
export function sqlQuery(sql: string): Promise<any> {
  return new Promise((resolve, reject) => {
    pool.getConnection(function (err, $sql) {
      $sql.query(sql, (err, result) => {
        if (err) {
          reject(err);
          return console.log("错误");
        }
        resolve(result);
        $sql.release();
      });
    });
  });
}
const getWhere = (arr: IWheres) => {
  let strArr: string[] = [];
  if (typeof arr === "string") {
    return arr;
  }
  arr.forEach((item, index) => {
    if (typeof item === "string") {
      strArr.push(item);
      return;
    }
    let str = "";
    const [key, symbol, val] = item;
    strArr.push(`${key} ${symbol} '${val}'`);
  });
  return strArr.join(" and ");
};

const getType = (type: string) => {
  switch (type) {
    case "update":
      return "INSERT INTO ";
      break;
    default:
      return "select ";
      break;
  }
};

export function model(sql: Idb) {
  const { table, field, where, order, type } = sql;
  
  let query: string;
  query+=getType(type)
  query+=`${table}`




}
model.prototype.select = () => {};
model.prototype.find = () => {};
